package com.yanqu.road.server.cmd.activity.dafuweng;

import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.activity.dafuweng.DFWConfig;
import com.yanqu.road.pb.monopoly.MonopolyProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.activity.ActivityMgr;
import com.yanqu.road.server.manger.activity.dafuweng.DaFuWengMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.GameProtocol;

@Cmd(code = GameProtocol.S_DA_FU_WENG_BATTLE_BOSS, desc = "打boss")
public class DaFuWengBattleBossCmd extends AbstractCommand {

    private int bossId;

    // 1.事件免费打Boss，2.事件追捕Boss，3.商会打Boss，4.快速击杀boss
    private int type;

    private boolean useProp;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        MonopolyProto.BattleBossReqMsg reqMsg = MonopolyProto.BattleBossReqMsg.parseFrom(packet.getBytes());
        bossId = reqMsg.getBossId();
        type = reqMsg.getType();
        useProp = reqMsg.getUseProp();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        DFWConfig dfWConfig = DaFuWengMgr.getDfwConfig();
        ActivityInfo activityInfo = dfWConfig.getActivityInfo();
        if (!ActivityMgr.activityInTime(activityInfo)) {
            ret = GameErrorCode.E_ACTIVITY_DFW_NO_IN_TIME;
            return;
        }
        DaFuWengMgr.battleBoss(dfWConfig, player, bossId, type, useProp);
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret != 0) {
            MonopolyProto.BattleBossRespMsg.Builder builder = MonopolyProto.BattleBossRespMsg.newBuilder();
            builder.setRet(ret);
            player.sendPacket(ClientProtocol.U_DA_FU_WENG_BATTLE_BOSS, builder);
        }
    }
}
